import requests
import json
from urllib.parse import quote

_headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
}

def _make_url(url, **kwargs):
    req_params = '&'.join([f'{k}={quote(str(v),safe="")}' for k, v in kwargs.items()])
    if req_params:
        url += '?'+req_params
    return url

def get(url, headers=_headers, **kwargs):
    return requests.get(_make_url(url, **kwargs), headers=headers)

def post(url, headers=_headers, **kwargs):
    return requests.post(url,data=json.dumps(kwargs) , headers=headers)

def get_json(url, headers=_headers, **kwargs):
    return get(url, headers=headers, **kwargs).json()

def post_json(url, headers=_headers, **kwargs):
    return post(url, headers=headers, **kwargs).json()

def tidy(data):
    return [x for x in data]

async def aget(url, headers=_headers, **kwargs):
    import httpx
    url = _make_url(url, **kwargs)
    async with httpx.AsyncClient() as client:
        return await client.get(url, headers=headers)